Temp: Proposal for ComposedWebView #845
Draft
+145
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a proposal for a refactoring on our WebView management.
What I'm waiting from you are some feedback on the proposal, if you think is a good idea or not. I'm currently stuck on the implementation and I don't want to invest more time until I'm sure it is the good direction.
Problem
Today our codebase structure is the following:
Each WebView component has a hard-coded reference to its WebView child (i.e
CozyWebView
defines that its child is aReloadInterceptorWebView
)This makes difficult to add a layer to the WebView's tree, or to invert some of them in the hierarchy.
Imagine that we want to add a
ReloadableWebView
that embed ALL of our webviews and allows to unmount/remount everything when we want a reload (so we enforce the proxywebview to generate a new HTML)To make this we would have to edit
HomeView
to use aReloadableWebView
instead ofCozyProxyWebView
, to hard codeReloadableWebView
withCozyProxyWebView
as child, and then we should remember to search for all otherCozyProxyWebView
references in the code and replaceCozyProxyWebView
byReloadableWebView
like we did inHomeView
Here would be the new codebase structure
So my question is
How can we make this more flexible?
Proposal
My proposal is to create a
ComposedWebView
that would allow developers to "compose" their WebView like they want.The API would be like this:
Which would be translated on runtime as the following
This would allow to easily add/remove parts. If we want to remove the
ReloadInterceptorWebView
from the generated tree then we can do:If we want to add a
ReloadableWebView
on the top level then we can do:Work in progress
This PR is a draft implementation for this concept.
src/components/webviews/ComposedWebView.js
contains the logic that translates the flat declaration into a nested WebView tree on runtime.This would have some repercussions on the way we create WebViews:
forwardRef
ChildWebview
prop defaulted toWebView
and use it as their childonShouldStartLoadWithRequest
should consider they can have a parent and call it if exists